package com.ruoyi.web.controller.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.module.domain.WithdrawalAmount;
import com.ruoyi.module.service.IWithdrawalAmountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 提现管理Controller
 *
 * @author fubojin
 * @date 2025-01-10
 */
@RestController
@RequestMapping("/admin/amount")
public class WithdrawalAmountController extends BaseController
{
    @Autowired
    private IWithdrawalAmountService withdrawalAmountService;

    /**
     * 查询提现管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WithdrawalAmount withdrawalAmount)
    {
        startPage();
        List<WithdrawalAmount> list = withdrawalAmountService.selectWithdrawalAmountList(withdrawalAmount);
        return getDataTable(list);
    }

    /**
     * 导出提现管理列表
     */
    @Log(title = "提现管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WithdrawalAmount withdrawalAmount)
    {
        List<WithdrawalAmount> list = withdrawalAmountService.selectWithdrawalAmountList(withdrawalAmount);
        ExcelUtil<WithdrawalAmount> util = new ExcelUtil<WithdrawalAmount>(WithdrawalAmount.class);
        util.exportExcel(response, list, "提现管理数据");
    }

    /**
     * 获取提现管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(withdrawalAmountService.selectWithdrawalAmountById(id));
    }
    /**
     * 提现审核（通过）
     */
    @PostMapping(value = "approve/{id}")
    public AjaxResult approve(@PathVariable("id") Long id){
        return success(withdrawalAmountService.approve(id));
    }

    /**
     * 提现审核（拒绝）
     */
    @PostMapping(value = "reject/{id}")
    public AjaxResult reject(@PathVariable("id") Long id, @RequestParam String auditReason){
        return success(withdrawalAmountService.reject(id,auditReason));
    }

    /**
     * 提现（取消）
     */
    @PostMapping(value = "cancel/{id}")
    public AjaxResult cancel(@PathVariable("id") Long id){
        return success(withdrawalAmountService.cancel(id));
    }

    /**
     * 新增提现管理
     */
    @Log(title = "提现管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WithdrawalAmount withdrawalAmount)
    {
        return toAjax(withdrawalAmountService.insertWithdrawalAmount(withdrawalAmount));
    }

    /**
     * 修改提现管理
     */
    @Log(title = "提现管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WithdrawalAmount withdrawalAmount)
    {
        return toAjax(withdrawalAmountService.updateWithdrawalAmount(withdrawalAmount));
    }

    /**
     * 删除提现管理
     */
    @Log(title = "提现管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(withdrawalAmountService.deleteWithdrawalAmountByIds(ids));
    }
}
